<?php

namespace App\Service\Collect;


use App\Service\BaiduNlp;
use QL\QueryList;

class Baidu extends Base
{
    // 从百家号采集
    protected $domain;
    protected $site_id   = 10;
    protected $site_name = '百家号';

    // 初始化
    protected function init()
    {
        parent::init();
    }


    // 保存到数据表
    public function saveApiDataToDb($_item, $key, $is_file = false)
    {
        // 执行采集
        $_title = trim($_item['title']);
        $_href  = trim($_item['href']);
        $_desc  = trim($_item['describe']);
        $_html  = trim($_item['html']);
        $_time  = trim($_item['time']);
        $_text  = '';
        $_cover = trim($_item['cover']);
        $images = [];

        // HTML里面有json的内容
        $startString  = '<!--s-data:';
        $endString    = '}-->';
        $startLength  = strpos($_html, $startString);
        $endLength    = strpos($_html, $endString);
        $startStrlen  = strlen($startString);
        $endStrlen    = strlen($endString);
        $_jsonString  = substr($_html, $startLength + $startStrlen, $endLength - $startLength - $startStrlen + 1);
        $_json        = json_decode($_jsonString, true);  // 可能返回为空
        $j_title      = $this->removeHtml($_json['title']);
        $j_href       = $_json['titleUrl'];
        $j_desc       = $_json['summary'];
        $j_authorLogo = $_json['sourceIcon'];
        $j_cover      = $_json['leftImgSrc'];
        $j_author     = $_json['sourceName'];
        //$j_author    = $_json['maskIcon'];
        if(!empty($_json['dispTime'])){
            $j_date  = $_json['dispTime'];
            $j_ctime = strtotime(str_replace(['年', '月', '日'], ['-', '-', ''], $_json['dispTime']));
        } else{
            $j_date  = '';
            $j_ctime = '';
        }
        // HTML里面有json的内容  结束
        //echo '<pre>';
        //echo chr(10);
        //var_dump($_json);

        // TODO 百度安全验证
        // 采集地址
        //$_href = $this->realHref($_href);
        //$_href = 'http://baijiahao.baidu.com/s?id=1762259842593990843';

        // 百家号链接：https://baijiahao.baidu.com/s?id=1762259842593990843&wfr=spider&for=pc
        // 百家号才采集详情，其他不采集详情
        $isBaijia = false;
        if(strpos($_href, '//baijiahao.baidu.com') !== false){
            $isBaijia = true;
            $_href    = str_replace('https', 'http', $_href);
        }


        // 判断链接是否已经采集
        if($is_file){
            $info = $this->isGatherFile($_href);
        } else{
            $info = $this->isGather($_href);
        }
        if($info){
            if(empty($info['sentiment'])){
                $sentiment = $this->baiduNlp($info['text'] ?: $info['description']);
                if($sentiment){
                    if($is_file){
                        $info['sentiment'] = $sentiment;
                        $this->updateFile($_href, $info);
                    } else{
                        $this->updateArticle($info['id'], ['sentiment' => $sentiment]);
                    }
                }
            }

            return $this->return_false(' '.($key + 1).'：==> 已经采集文章：'.$_title);
        }
        // 如果没有标题
        /*if(empty($_title)){
            return $this->return_false(' '.($key + 1).'：==> 文章：没有标题，不能采集：'.$_title);
        }*/

        // 执行采集
        if($isBaijia){
            //$this->showMsg(' '.($key + 1).'：==> 采集文章：'.$_title);
            $domain = parse_url($_href, PHP_URL_HOST);
            $header = $this->getHeader($domain);
            try{
                $html = $this->apiCurl()->header($header)->url($_href)->request();
            } catch(\Exception $e){
                return $this->return_false($e->getMessage());
            }

            $_ql     = QueryList::html($html);
            $_title  = $_ql->find('#ssr-content-wrapper #ssr-content ._2jN0Z .q1J1i .EaCvy ._3tNyU #header  .sKHSJ')->text();
            $_author = $_ql->find('#ssr-content-wrapper #ssr-content ._2jN0Z .q1J1i .EaCvy ._3tNyU #header  .bH7m7 ._1HGmt a')->text();
            $_time   = $_ql->find('#ssr-content-wrapper #ssr-content ._2jN0Z .q1J1i .EaCvy ._3tNyU #header  .bH7m7 ._2sjh9')->text();
            $_ctime  = strtotime($_time);

            // 只采集今天的
            if($this->startTime && ($_ctime < $this->startTime)){
                return $this->return_die(' '.($key + 1).'：==> 文章：是以前过期的文章，不采集：'.$_title);
            }


            // 内容与图片
            $rule = ['html' => ['', 'html'], 'text' => ['', 'text'], 'img' => ['img', 'src'],];
            $rule = ['text' => ['', 'text'], 'img' => ['img', 'src'],];
            $list = $_ql->range('#ssr-content-wrapper #ssr-content ._2jN0Z .q1J1i .EaCvy ._18p7x p')->rules($rule)->queryData();
            foreach($list as $item){
                if($item['img']){
                    $images[] = $item['img'];
                    if(empty($_cover)){
                        $_cover = $item['img'];
                    }
                }
                if(empty($_desc)){
                    $_desc = trim($item['text']);
                }
            }
            if(empty($_desc)){
                $_desc = trim($_text);
            }

            // 站点信息
            $_channel  = '';
            $from_site = '百度百家号';
            $site_id   = 10;
        } else{
            $_author = $j_author;
            if(empty($_href)){
                $_href = $j_href;
            }
            if(strpos($j_author, '云财经网') !== false){
                return $this->return_false(' '.($key + 1).'：==> 文章：来自云财经网，不能采集：'.$_title);
            }
            if(empty($_desc)){
                $_desc = $j_desc;
            }
            if(empty($_title)){
                $_title = $j_title;
            }
            if(empty($_cover)){
                $_cover = $j_cover;
            }
            // 发布时间
            if($_time){
                if(strpos($_time, '天前') > 0){
                    //var_dump(strtotime("-7 days"));
                    $_ctime = strtotime('-'.substr($_time, 0, strpos($_time, '天前')).' days');
                } else{
                    $_ctime = strtotime(str_replace(['年', '月', '日'], ['-', '-', ''], $_time));
                }
            }
            if(empty($j_ctime) && empty($_ctime)){
                return $this->return_false(' '.($key + 1).'：==> 没有时间，不采集 采集文章：'.$j_title);
            }
            if(empty($_ctime)){
                $_ctime = $j_ctime;
            }
            // 只采集今天的
            if($this->startTime && ($_ctime < $this->startTime)){
                return $this->return_die(' '.($key + 1).'：==> 文章：是以前过期的文章，不采集：'.$_title);
            }

            // 站点信息
            $_channel  = '';
            $from_site = '百度资讯-媒体网站';
            $site_id   = 12;
        }

        // 全匹配 精准匹配
        if((strpos($_desc, $this->keyword) === false) && strpos($_title, $this->keyword) === false){
            return $this->return_false('==> 文章：文章没有精准匹配到搜索的关键字！');
        }
        // 排除关键字 宋正兴
        if(($this->keyword == '董事长宋正') && (strpos($_desc, '宋正兴') !== false) || strpos($_title, '宋正兴') !== false){
            return $this->return_false('==> 文章：文章匹配到其他关键词！');
        }

        // 判断 情感倾向
        //  "sentiment":2,   // 表示情感极性分类结果，0:负向，1:中性，2:正向
        /* $sentiment = '';  // 默认
        $full      = [0 => '负向', 1 => '中性', 2 => '正向'];
        $result    = (new BaiduNlp())->sentiment($_desc);
        if(isset($result['items'][0]['sentiment'])){
            $sentiment = $full[$result['items'][0]['sentiment']] ?? $sentiment;
        } */
        $sentiment = $this->baiduNlp($_desc);

        // 整理保存的数据
        $_row = [
            'channel'      => 'article',
            'sentiment'    => $sentiment,
            'link'         => $_href,
            'title'        => trim($_title),
            'description'  => $_desc,
            'text'         => $_desc,
            'time'         => $_ctime,
            'images'       => $images,
            'cover'        => $_cover,
            'author'       => trim($_author),
            'from_channel' => $_channel,
            'from_site'    => $from_site,
            'site_id'      => $site_id,
        ];

        //var_dump($_row);
        if($is_file){
            $res = $this->saveFile($_row);
        } else{
            $res = $this->saveArticle($_row);
        }

        return $res;
    }

    // 采集详情测试
    public function getShowTest()
    {
        $url    = 'http://baijiahao.baidu.com/s?id=1762259842593990843&wfr=spider&for=pc';
        $domain = parse_url($url, PHP_URL_HOST);
        $refer  = substr($url, 0, strpos($url, 'com/') + 4);
        $refer  = 'http://www.baidu.com/s?ie=utf-8&medium=2&tn=news&rtt=4&bsst=1&cl=2&f=8&rsv_btype=t&rsv_bp=1&oq=&cl=2&rsv_dl=news_t_sk&wd=易见股份';

        // 获取 cookie
        /*$header = $this->getHeader($domain);
        $res    = $this->apiCurl()->header($header)->returnHeader(true)->url($refer)->request();
        $cookie = implode(';', $res['cookies']);*/

        /*$cacheName = 'collect_baidubaijia';
        $cookie    = Cache::get($cacheName);
        var_dump($cookie);*/

        try{
            $header = $this->getHeader($domain);
            $html   = $this->apiCurl()->header($header)->returnHeader(true)->url($url)->request();
            $cookie = implode(';', $html['cookies']);
        } catch(\Exception $e){
            return $this->return_false($e->getMessage());
        }


        //Cache::put($cacheName, $cookie);

        var_dump($html['content']);
    }


    // 获取api接口的列表(测试)
    //   没有翻页，全部获取
    public function getApiList($keyword, $type = 'baijiahao', $page = 1, $size = 10)
    {
        if(empty($keyword)){
            return $this->return_false('传递采集关键字！');
        }

        // 每个列表中有每个内容的json，已经被注释了的，还可以提取出来使用
        $rule = [
            'title'    => ['div h3', 'text'],
            'href'     => ['div h3 a', 'href'],
            'describe' => ['div div span.c-color-text', 'text'],
            'cover'    => ['div .c-span3 div img', 'src'],
            'time'     => ['div div span.c-color-gray2', 'text'],
            //'author'   => ['div div div.news-source_Xj4Dv', 'text'],
            'html'     => ['div', 'html'],   // 在html中有各种具体内容的json，被注释了的，还可以提取出来使用
        ];

        // TODO 采集百度 必须是http 不能是https
        //   https://www.baidu.com/s?medium=2&ie=utf-8&tn=news&rtt=4&bsst=1&cl=2&wd=易见股份
        //   https://www.baidu.com/s?ie=utf-8&medium=2&tn=news&rtt=4&bsst=1&cl=2&f=8&rsv_btype=t&rsv_bp=1&oq=&cl=2&rsv_dl=news_t_sk&wd=易见股份
        try{
            // 百家号链接
            $start = ($page - 1) * $size;
            if($type == 'baijiahao'){
                $url = 'http://www.baidu.com/s?ie=utf-8&medium=2&tn=news&rtt=4&bsst=1&cl=2&f=8&rsv_btype=t&rsv_bp=1&oq=&cl=2&rsv_dl=news_t_sk&wd='.$keyword.'&pn='.$start;
            } else{
                // 新闻媒体链接
                $url = 'http://www.baidu.com/s?ie=utf-8&medium=1&rtt=4&bsst=1&rsv_dl=news_b_pn&cl=2&wd='.$keyword.'&tn=news&rsv_bp=1&tfflag=0&tngroupname=organic_news&newVideo=12&goods_entry_switch=1&pn='.$start;
            }
            $lists = $this->getQLList($url, '#wrapper #wrapper_wrapper #container #content_left', 'div.result-op', $rule);
        } catch(\Exception $e){
            return $this->return_false($e->getMessage());
        }

        // 百度没有为空的时候 默认大于最后一页的翻页都是返回最后 一页的数据
        if(empty($lists)){
            $string = $type == 'baijiahao' ? '百度百家号' : '百度网站';

            return $this->return_die($string.'：没有采集内容：'.$keyword.' 当前页数：'.$page.'  每页数量：'.$size);
        }

        return $lists;
    }


    // header参数
    protected function getHeader($domain, $cookie = '')
    {
        // 现在的 cookie
        /*if(empty($cookie)){
            $cookie = 'H_WISE_SIDS=40154_40169_39661_40211_40217_40223_40256_40294_40291_40289_40317_40080_40364_40352_40304_40374; BDUSS_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ZM-t7yajK2KrT-mJ85l7h0qnPJJKChUQpQT8rbn_OK5OiJPjgoj6Kab3vOUnTXpO15T8zBN5thURB2DkO-4bCWJ5TMl5jDh3Mb6ksDhAtqj0OtJ4f_CPbfbTDjJRYh4t_-P6Mbl6AWMT-0bFHKKbYBR5-qJ3lMjoY0-DvLnodQqc3Kan7_JjO3PTSs-j9LfJ0jq49ehJOhfQxtNRn0DnjtpkM8t5YWMbobUPUWMJ9LUvftgcdot5yBbc8eIna5hjkbfJBQttjQn3hfIkjXIKLK-oj-D_Gej053f; PSINO=6; BA_HECTOR=00a0a0ahal0404848ga58g24u14b5a1iul5pu1t; ZFY=Uh0DbIZTcAtOEKHZJx:AT6pTBgEZv:AmF0ON3EpeikZbA:C; delPer=0; H_PS_PSSID=40206_40223_40248_40295_40291_40289_40284_40317_40319_40080_40365_40351_40381_40367_40358; H_WISE_SIDS_BFESS=40154_40169_39661_40211_40217_40223_40256_40294_40291_40289_40317_40080_40364_40352_40304_40374; ab_sr=1.0.1_ZDE5NWFlZWQ3MTYwOGZiNDMwYThiMGRhODA0YzNkNmQ1MmVmNjFhMmM4ZGY4OGNmM2E5NTc3ZTI4MTJjNWExYTRjYzA4YWUwZWQ4ZTU0ODdmNmFmNjM2MzgyOWQ2MmM5ZDA3OWNhMjg4YzIxMTc3NzIwMGVmM2NjMWI3MmUwZWIwNjMxOTVmNzlmZmUxOTQ2NzYzZjVkZTBjZjQ1ZTMwNQ==';
        }*/

        // 以前的 cookie
        /*if(empty($cookie)){
            $cookie =  'BIDUPSID=FEB571C3FA73AE59B410825660BF707B; PSTM=1702538763; BAIDUID=87044769BBB35ACAF91DD21A00064796:FG=1; BDUSS=W9-em9QeUdCUVdPNm9xYWRaSFhqWlEtdDF5Z3E5eDZ5VU9RT21yNzNsQ0htZDVsSVFBQUFBJCQAAAAAAQAAAAEAAAAqv0N~AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIcMt2WHDLdlN; BDUSS_BFESS=W9-em9QeUdCUVdPNm9xYWRaSFhqWlEtdDF5Z3E5eDZ5VU9RT21yNzNsQ0htZDVsSVFBQUFBJCQAAAAAAQAAAAEAAAAqv0N~AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIcMt2WHDLdlN; BD_UPN=12314753; MCITY=-75%3A; H_WISE_SIDS=110085_287175_292122_295129_281879_296147_294385_296976_294860_297751_296454_292169_294756_298309_298225_298228; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; H_WISE_SIDS_BFESS=110085_287175_292122_295129_281879_296147_294385_296976_294860_297751_296454_292169_294756_298309_298225_298228; BA_HECTOR=848120akag2gagal2gal8h84bu29i91iucv4v1s; BAIDUID_BFESS=87044769BBB35ACAF91DD21A00064796:FG=1; ZFY=Uh0DbIZTcAtOEKHZJx:AT6pTBgEZv:AmF0ON3EpeikZbA:C; delPer=0; BD_CK_SAM=1; PSINO=6; shifen[611487516154_45758]=1709604562; COOKIE_SESSION=142413_6_7_6_11_15_0_3_6_4_0_3_117_142410_0_7_1709461847_1709604566_1709604559%7C9%23142413_20_1709604559%7C9; shifen[668056444524_69630]=1709604564; BCLID=11454338310476152276; BCLID_BFESS=11454338310476152276; BDSFRCVID=RP0OJeC62ZRIaI7qTlqDMPbDC1TkOzoTH6aoRebjw7oKbOuQoFICEG0Pgx8g0K4M4Mf4ogKKXgOTHw0F_2uxOjjg8UtVJeC6EG0Ptf8g0x5; BDSFRCVID_BFESS=RP0OJeC62ZRIaI7qTlqDMPbDC1TkOzoTH6aoRebjw7oKbOuQoFICEG0Pgx8g0K4M4Mf4ogKKXgOTHw0F_2uxOjjg8UtVJeC6EG0Ptf8g0x5; H_BDCLCKID_SF=JnkfVIP-tI83fP36q4jE2RIs-qO-etJyaR3q0qQvWJ5TMCoz0Po835LL3M5fBfrTKen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k-PnVeU0ILtnZKxtqtDjg0RcmJ4jxHlj-Xq3DQMthb-Cj54RnWncKW56lHl82qUbP2t7bK4t4-tQ405OTKKFO0KJcbl6KOnQmhPJvypksXnO7-5OlXbrtXp7_2J0WStbKy4oTjxL1Db3JKjvMtIFtVD02fI-BMI-r5nJbq4I0MM_X5-Cs5RPL2hcH0KLKJbrtyR3DKq0V2MQuQPjR0K7UKf7kJMb1MRjveJ5mbl-hb-7C2nj0BjbOXq5TtUJ2SDnTDMRhqtkPXM6yKMniyIv9-pn5tpQrh459XP68bTkA5bjZKxtq3mkjbPbDfn02eCKujT8Wj5cWjaRf-b-X2jT306rJaDkK_U7Oy4oTj6Dbh45ZJh3DQIJD0q6xKqbTepkGK4Jo3MvB-fP8bqOhQ5Qbapjs-JTFJ-nuQft20b8AeMtjBbLL2g5rBJ7jWhviep72ybt2QlRX5q79atTMfNTJ-qcH0KQpsIJM5-DWbT8EjHCtJT_tJRFf_Cv5b-0_DJ5k5-QVhPjH-UnLqhjTtgOZ0l8KtfcCOJjVjnQxhb_vXJ3a0UtDQI39XJ7mWIQHDUoN-46bjP4U-4ntQ4RlWm74KKJx5-PWeIJojMFMXt53hUJiBhvMBan7LKJIXKohJh7FM4tW3J0ZyxomtfQxtNRJ0DnjtPPhbRO4-TF5jjc3DM5; H_PS_PSSID=40154_40169_39661_40211_40217_40223_40256_40294_40291_40289_40317_40080_40364_40352; H_PS_645EC=5fcfqTCKFKXWmw7du325niKVdO5E3nP9x6m9dLj6TvQf5L%2BpVlevYv4WMjg; B64_BOT=1; RT="z=1&dm=baidu.com&si=682f928e-67e4-4512-b07a-b627441a3eee&ss=lte2u2k9&sl=0&tt=0&bcn=https%3A%2F%2Ffclog.baidu.com%2Flog%2Fweirwood%3Ftype%3Dperf&ul=bz&hd=nj"; BDRCVFR[C0p6oIjvx-c]=mk3SLVN4HKm; BDRCVFR[dG2JNJb_ajR]=mk3SLVN4HKm; userFrom=null; ab_sr=1.0.1_MTM3NWUxMzlhMzNkZmIwOTYyYTJlYTRmMzY4NGFkZjQ2NjIyYzk3NjEzNGY2ZjM1NzZlZTVlY2Y2MDQzMWFiOTZiNzE3ODU3MWE3ODlhMzk4ODA0YzgwZGNmMWE1YzZmZGU4NTAyZTRkOWU1YWM0NzFiMGNmNWI3NGZkY2EwNjEzNDFmMjBmNzVkN2NmZjMzZDk2OGExMjVkYmUxMmUxNw==; BDRCVFR[-pGxjrCMryR]=mk3SLVN4HKm; BDSVRTM=352';
        }*/

        if(empty($cookie)){
            $cookie = 'BDUSS=W9-em9QeUdCUVdPNm9xYWRaSFhqWlEtdDF5Z3E5eDZ5VU9RT21yNzNsQ0htZDVsSVFBQUFBJCQAAAAAAQAAAAEAAAAqv0N~AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIcMt2WHDLdlN';
        }

        return [
            //'Host:www.baidu.com',
            //'Host:baijiahao.baidu.com',
            'Host:'.$domain,
            'Cookie:'.$cookie,
            'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
            //'Accept-Encoding: gzip, deflate, br',
            'Accept-Language:zh-CN,zh;q=0.9',
            'Connection:keep-alive',
            'Cache-Control:max-age=0',
            //'Referer:https://www.baidu.com/s?rtt=1&bsst=1&cl=2&tn=news&ie=utf-8&word=%E6%98%93%E8%A7%81%E8%82%A1%E4%BB%BD',
            'Sec-Ch-Ua:"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
            'Sec-Ch-Ua-Mobile:?0',
            'Sec-Ch-Ua-Platform:"Windows"',
            'Sec-Fetch-Dest:document',
            'Sec-Fetch-Mode:navigate',
            'Sec-Fetch-Site:same-origin',
            'Sec-Fetch-User:?1',
            'Upgrade-Insecure-Requests:1',
            'User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36',
        ];
    }
}

